package com.demo.config.rabbitMq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 交换机和队列配置-topic-生产者
 *
 * @author admin
 */
@Configuration
public class RabbitConfigTopic {

	// @Resource
	// ConnectionFactory connectionFactory;
	@Bean
	public Queue topicQueue() {
		return new Queue("topic_queue");
	}

	@Bean
	public Queue topicQueue2() {
		return new Queue("topic_queue2");
	}

	@Bean
	public TopicExchange topicExchange() {
		return new TopicExchange("topicExchange");
	}

	// 绑定队列与交换机
	@Bean
	public Binding bindingtopic() {
		// return
		// BindingBuilder.bind(topicQueue()).to(topicExchange()).with("topic.order.id");

		// BindingBuilder.bind(topicQueue()).to(topicExchange()).with("topic.*.qwerty");
		// BindingBuilder.bind(队列(Queue)).to(交换机(Exchange)).with(路由规则(Routing Key));
		return BindingBuilder.bind(topicQueue()).to(topicExchange()).with("qwerasdfv");
	}

	@Bean
	public Binding bindingtopic2() {
		return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("#.goods");
	}

	// @Bean
	// public SimpleRabbitListenerContainerFactory consumerBatchContainerFactory() {
	// SimpleRabbitListenerContainerFactory factory = new
	// SimpleRabbitListenerContainerFactory();
	// factory.setConnectionFactory(
	// (org.springframework.amqp.rabbit.connection.ConnectionFactory) connectionFactory);
	// //配置手动确认
	// factory.setAcknowledgeMode(AcknowledgeMode.MANUAL);
	// factory.setConcurrentConsumers(1);
	// factory.setMaxConcurrentConsumers(1);
	// return factory;
	// }

}
